# -*- coding: utf-8 -*-

from reportlab.lib.pagesizes import A4
from geraldo import Report, ReportBand, Label, ObjectValue, SystemField, BAND_WIDTH, FIELD_ACTION_COUNT, Rect
from reportlab.lib.units import cm
from reportlab.lib.enums import TA_CENTER, TA_RIGHT, TA_LEFT
from reportlab.lib.colors import black, white

class ServicoInternoReport(Report):
    author = 'CBTU - Companhia Brasileira de Trens Urbanos'
    print_if_empty = True
    page_size = A4

    class band_summary(ReportBand):
        height = 0.8*cm
        elements = [
            Label(text="Serviços:", top=0.1*cm, left=0*cm),
            ObjectValue(attribute_name='id', top=0.1*cm, left=1.75*cm,\
                action=FIELD_ACTION_COUNT, display_format=u'%s serviço(s) encontrado(s)'),
        ]
        borders = {'top': True}

    class band_page_header(ReportBand):
        height = 1.75*cm
        elements = [
            Rect(width=BAND_WIDTH, height=0.6*cm, left=0, top=1.1*cm, fill_color=black, fill=True, _test_temp=True),
            SystemField(expression='%(var:titulo)s', top=0, left=0, width=BAND_WIDTH,
                style={'fontName': 'Helvetica-Bold', 'fontSize': 14, 'alignment': TA_CENTER}),
            Label(text="Status", top=1.2*cm, left=0*cm, width=3*cm,
                  style={'alignment':TA_CENTER, 'textColor': white, 'fontName': 'Helvetica-Bold'},),
            Label(text="Número", top=1.2*cm, left=3.1*cm, width=3*cm,
                  style={'alignment':TA_CENTER, 'textColor': white, 'fontName': 'Helvetica-Bold'},),
            Label(text="Setor", top=1.2*cm, left=6.2*cm, width=3*cm,
                  style={'alignment':TA_CENTER, 'textColor': white, 'fontName': 'Helvetica-Bold'},),
            Label(text="Data Emissão", top=1.2*cm, left=9.3*cm, width=3*cm,
                  style={'alignment':TA_CENTER, 'textColor': white, 'fontName': 'Helvetica-Bold'},),
            Label(text="Equipe", top=1.2*cm, left=12.4*cm, width=3*cm,
                  style={'alignment':TA_CENTER, 'textColor': white, 'fontName': 'Helvetica-Bold'},),
            Label(text="Estação", top=1.2*cm, left=15.5*cm, width=3*cm,
                  style={'alignment':TA_CENTER, 'textColor': white, 'fontName': 'Helvetica-Bold'},),
                  ]

    class band_page_footer(ReportBand):
        height = 0.5*cm
        elements = [
            SystemField(expression='Página # %(page_number)d de %(page_count)d', top=0.1*cm,
                width=BAND_WIDTH, style={'alignment': TA_RIGHT}),
        ]
        borders = {'top': True}

    class band_detail(ReportBand):
        height = 0.6*cm
        display_inline = True
        elements=[
                ObjectValue(attribute_name='status', width=3*cm, left=0.075*cm, top=0.09*cm, 
                            style={'alignment':TA_LEFT, 'borderPadding': 2, 'borderWidth': 0.5, 'borderColor': black,}, 
                            ),
                ObjectValue(attribute_name='numero', width=3*cm, left=3.24*cm, top=0.09*cm,
                            style={'alignment':TA_LEFT, 'borderPadding': 2, 'borderWidth': 0.75, 'borderColor': black,},
                            ),
                ObjectValue(attribute_name='setor', width=3*cm, left=6.36*cm, top=0.09*cm,
                            style={'alignment':TA_LEFT, 'borderPadding': 2, 'borderWidth': 0.75, 'borderColor': black,},
                            ),
                ObjectValue(attribute_name='get_data_emissao', width=3*cm, left=9.48*cm, top=0.09*cm, 
                            style={'alignment':TA_LEFT, 'borderPadding': 2, 'borderWidth': 0.5, 'borderColor': black,}, 
                            ),
                ObjectValue(attribute_name='equipe', width=3*cm, left=12.6*cm, top=0.09*cm,
                            style={'alignment':TA_LEFT, 'borderPadding': 2, 'borderWidth': 0.75, 'borderColor': black,},
                            ),
                ObjectValue(attribute_name='estacao', width=3.2*cm, left=15.72*cm, top=0.09*cm,
                            style={'alignment':TA_LEFT, 'borderPadding': 2, 'borderWidth': 0.75, 'borderColor': black,},
                            ),
                ]
        borders = {'all': True}
